package org.mtmi.ui.scenes.actions;

import org.mtmi.ui.IMG;
import org.mtmi.ui.M;
import org.mtmi.ui.actions.Action;
import org.mtmi.ui.controls.listeners.PopupListener;
import org.mtmi.ui.controls.popups.AbstractButtonPopup;
import org.mtmi.ui.drawables.IDrawable;
import org.mtmi.ui.scenes.ChooseSceneBackgroundPopup;
import org.mtmi.ui.scenes.Scene;
import org.mtmi.ui.scenes.SceneManager;

/**
 * Display a popup with available scene background, and change it if needed.
 */
public class ChangeSceneBackgroundAction extends Action
{
	private IDrawable image;
	
	public ChangeSceneBackgroundAction() {
		super( PUSH );
	}
	
	@Override
	public String getText() {
		return "Change Scene Background";
	}
	
	@Override
	public IDrawable getImage() {
		if( image==null ) {
			image = IMG.GetD( IMG.I_SCENE_CHANGE_ICON );
		}
		return image;
	}
	
	@Override
	public boolean isEnabled() {
		return true;
	}
	
	@Override
	public void run() {
		final Scene scene = SceneManager.getDefault().getScene();
		final ChooseSceneBackgroundPopup p = new ChooseSceneBackgroundPopup( scene, M.SCENE_EDITOR_CONTROL );
		p.addResponseListener( new PopupListener() {
			@Override
			public void popupButtonSelected(int id) {
				if( id == AbstractButtonPopup.OK ) {
					scene.setBackgroundKey( p.getBackgroundKey() );
					scene.redraw();
				}
			}
		});
	}
}
